<html>
<head><meta charset="utf-8"><title>New API for assists · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html">New API for assists</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="196764520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196764520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196764520">(May 07 2020 at 12:48)</a>:</h4>
<p>Hey, in <a href="https://github.com/rust-analyzer/rust-analyzer/pull/4350" title="https://github.com/rust-analyzer/rust-analyzer/pull/4350">https://github.com/rust-analyzer/rust-analyzer/pull/4350</a> I propose to change our API for assists. I feel like the new version is better, but I want to bump the visibility of this, in case someone comes up with even a better improvement, before I refactored all 30-ish existing assists :)</p>



<a name="196764587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196764587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196764587">(May 07 2020 at 12:48)</a>:</h4>
<p>The new API mirrors the one from completions, where we split <code>&amp;</code> context and <code>&amp;mut</code> accumulator.</p>



<a name="196765021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196765021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196765021">(May 07 2020 at 12:52)</a>:</h4>
<p>The two main changes are:</p>
<ul>
<li>there's no awkwardness when <code>ctx</code> can't be captured into assist closure</li>
<li>we now return <code>Option&lt;()&gt;</code> rather than <code>Option&lt;Assist&gt;</code>, so groups and multi-assists become easier</li>
</ul>



<a name="196765582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196765582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Coenen Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196765582">(May 07 2020 at 12:56)</a>:</h4>
<p>Yay multi assists &lt;3</p>



<a name="196765909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196765909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Coenen Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196765909">(May 07 2020 at 12:59)</a>:</h4>
<p>I think it could also be easier with this refactor if as in completions we want to have a kind of scoring to manage assists orders</p>



<a name="196765967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196765967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196765967">(May 07 2020 at 12:59)</a>:</h4>
<p>For assist, we already have this actually</p>



<a name="196766074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196766074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Coenen Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196766074">(May 07 2020 at 13:00)</a>:</h4>
<p>Based on alphabetical order ?</p>



<a name="196766078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196766078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196766078">(May 07 2020 at 13:00)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/f4cd75ac06dff7f5a95065a6c3868669e5c2ab27/crates/ra_assists/src/lib.rs#L93" title="https://github.com/rust-analyzer/rust-analyzer/blob/f4cd75ac06dff7f5a95065a6c3868669e5c2ab27/crates/ra_assists/src/lib.rs#L93">https://github.com/rust-analyzer/rust-analyzer/blob/f4cd75ac06dff7f5a95065a6c3868669e5c2ab27/crates/ra_assists/src/lib.rs#L93</a></p>



<a name="196766114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196766114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Coenen Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196766114">(May 07 2020 at 13:00)</a>:</h4>
<p>Oh ok ! I missed it</p>



<a name="196766115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196766115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196766115">(May 07 2020 at 13:00)</a>:</h4>
<p>and then, solely for tie-breaking, <a href="https://github.com/rust-analyzer/rust-analyzer/blob/f4cd75ac06dff7f5a95065a6c3868669e5c2ab27/crates/ra_assists/src/lib.rs#L177-L180" title="https://github.com/rust-analyzer/rust-analyzer/blob/f4cd75ac06dff7f5a95065a6c3868669e5c2ab27/crates/ra_assists/src/lib.rs#L177-L180">https://github.com/rust-analyzer/rust-analyzer/blob/f4cd75ac06dff7f5a95065a6c3868669e5c2ab27/crates/ra_assists/src/lib.rs#L177-L180</a></p>



<a name="196766510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196766510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196766510">(May 07 2020 at 13:03)</a>:</h4>
<p>Why does it return <code>Option&lt;()&gt;</code> instead of <code>()</code>?</p>



<a name="196766912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196766912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196766912">(May 07 2020 at 13:06)</a>:</h4>
<p>That's a hack to make <code>?</code> work</p>



<a name="196766995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196766995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196766995">(May 07 2020 at 13:07)</a>:</h4>
<p>Ideally, it should return some ZST which is convertable from <code>NoneError</code>, but that's not stable yet</p>



<a name="196767065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196767065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Coenen Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196767065">(May 07 2020 at 13:08)</a>:</h4>
<p>What is ZST ? :)</p>



<a name="196767081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196767081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196767081">(May 07 2020 at 13:08)</a>:</h4>
<p>zero sized type</p>



<a name="196767099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196767099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Coenen Benjamin <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196767099">(May 07 2020 at 13:08)</a>:</h4>
<p>Ok sorry :)</p>



<a name="196767272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196767272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196767272">(May 07 2020 at 13:10)</a>:</h4>
<p>That's no reason to say sorry :) It's useful to know jargon, but we all at some point didn't know it</p>



<a name="196767849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196767849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196767849">(May 07 2020 at 13:15)</a>:</h4>
<p>What's the difference between an unresolved/resolved assist?</p>



<a name="196768027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196768027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196768027">(May 07 2020 at 13:17)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/assist_ctx.rs#L47-L77" title="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/assist_ctx.rs#L47-L77">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/assist_ctx.rs#L47-L77</a></p>



<a name="196768031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196768031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196768031">(May 07 2020 at 13:17)</a>:</h4>
<p>see these docs</p>



<a name="196768084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196768084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196768084">(May 07 2020 at 13:17)</a>:</h4>
<p>We want to optimize assists to only compute the edit if the user selected the assist</p>



<a name="196768158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196768158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196768158">(May 07 2020 at 13:18)</a>:</h4>
<p>We dont' do this in practice yet, (as LSP doesn't have <code>resolveAssist</code>), but our internal API is build around this idea</p>



<a name="196768188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/New%20API%20for%20assists/near/196768188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/New.20API.20for.20assists.html#196768188">(May 07 2020 at 13:18)</a>:</h4>
<p>(that's the reason for <code>-&gt; Option&lt;_&gt;</code> and closure-based <code>.add_assist</code>)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>